﻿#include "ssFBO.h"

namespace StarSeeker
{

ssFBO::ssFBO()
{
	m_handle = 0;
	m_target = GL_FRAMEBUFFER;
	m_err = 0;
}

ssFBO::~ssFBO()
{
	Delete();
}

bool ssFBO::Create()
{
	if (m_handle==0)
	{
		glGenFramebuffers(1, &m_handle);
	}
	return m_handle != 0;
}

void ssFBO::Delete()
{
	if (m_handle!=0)
	{
		glDeleteFramebuffers(1, &m_handle);
		m_handle = 0;
	}
}

void ssFBO::Use()
{
	if (m_handle!=0)
		glBindFramebuffer(m_target, m_handle);
}

void ssFBO::Nonuse()
{
	glBindFramebuffer(m_target, 0);
}

bool ssFBO::IsCreate()
{
	return m_handle > 0;
}

bool ssFBO::IsValid()
{
	m_err = glCheckFramebufferStatus(m_target);
	return m_err == GL_FRAMEBUFFER_COMPLETE;
}

void ssFBO::BindTexture(GLenum attachmentPoint, GLuint textureId)
{
	Use();
	glFramebufferTexture2D(m_target, attachmentPoint, GL_TEXTURE_2D, textureId, 0);
	Nonuse();
}

}
